package com.igrowing.easyRpc.server.tcp;

import com.igrowing.easyRpc.server.http.HttpServer;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.NetServer;

public class VertxTcpServer implements HttpServer {

    public static void main(String[] args) {
        new VertxTcpServer().doStart(8888);
    }

    /**
     * 处理请求
     * @return
     */

    @Override
    public void doStart(int port) {
        // 创建vertx实例
        Vertx vertx = Vertx.vertx();
        // 创建TCP服务器
        NetServer server = vertx.createNetServer();
        // 处理链接
        server.connectHandler(new TcpServerHandler());

        // 启动TCP服务并监听指定端口
        server.listen(port,result->{
            if (result.succeeded())
            {
                System.out.println("TCP server started on port "+ port);
            }
            else
            {
                System.out.println("Failed to started TCP server");
            }
        });
    }

}
